<?php

class highlightJs extends JsPlugin{
    
    static private $instance;
    public static function getInstanceOf($plugin){
        $class_name = __CLASS__;
        if (!isset(self::$instance))self::$instance = new $class_name($plugin);
        return self::$instance;
    } 
    
    public function init(){
        $this->LoadJsPlugin('jqueryui/jqueryui', 'jui');
        $this->Html->LoadJs("$this->url/js/jquery.highlight-3");
        $this->Html->LoadCss('plugins/jqueryui/highlight');
    }
    
    public function draw($words, $seletor){
        $this->LoadModel('search/alg', 'alg');
        $ignore = $this->alg->getIgnoredWords();
        if(is_array($words)){
            foreach($words as $wr){
                $wr = trim($wr);
                if(in_array($wr, $ignore)) continue;
                $wr = trim($this->alg->removePlural(trim($wr)));
                $this->Html->LoadJqueryFunction("$('$seletor').highlight('$wr');");
            }
        }else{
            $words = trim($this->alg->removePlural(trim($words)));
            $this->Html->LoadJqueryFunction("$('$seletor').highlight('$words');");
        }
        
    }
}

?>
